<?php

class InputController extends BaseController
{
	public $leftmenusTitle = '常用操作';
	
	
	protected function beforeAction($action)
    {
    	parent::beforeAction();
    	$this->leftmenus = array();    	
    	$this->leftmenus[] = array('href'=>$this->createUrl('input/newtreaty'),'menutext'=>'合约销售录入','isValid'=>Yii::app()->user->checkAccess('MENU2_HYXSLR'));
    	$this->leftmenus[] = array('href'=>$this->createUrl('input/newgeneral'),'menutext'=>'裸机销售录入','isValid'=>Yii::app()->user->checkAccess('MENU2_LJXSLR'));
    	$this->leftmenus[] = array('href'=>$this->createUrl('input/newlend'),'menutext'=>'产品外借录入','isValid'=>Yii::app()->user->checkAccess('MENU2_CPWJLR'));
    	$this->leftmenus[] = array('href'=>$this->createUrl('input/newpurchase'),'menutext'=>'商品请购录入','isValid'=>Yii::app()->user->checkAccess('MENU2_SPQGLR'));
    	
    	
    	Yii::app()->clientScript->registerCoreScript('jquery');
        return true;
    } 
	
	
	/**
	 * Declares class-based actions.
	 */
	public function actions()
	{
		return array(
			// captcha action renders the CAPTCHA image displayed on the contact page
			'captcha'=>array(
				'class'=>'CCaptchaAction',
				'backColor'=>0xFFFFFF,
			),
			// page action renders "static" pages stored under 'protected/views/site/pages'
			// They can be accessed via: index.php?r=site/page&view=FileName
			'page'=>array(
				'class'=>'CViewAction',
			),
		);
	}

	


	/**
	 * 新销售合约机
	 */
	public function actionNewtreaty()
	{
		//Yii::app()->clientScript->registerScriptFile(Yii::app()->createUrl('js/product'));
		Yii::app()->clientScript->registerScriptFile(Yii::app()->createUrl('js/common'));
		Yii::app()->clientScript->registerScriptFile(Yii::app()->createUrl('js/usertypeProducttype'));
		Yii::app()->clientScript->registerScriptFile(Yii::app()->createUrl('js/producttypeProduct'));

		$this->title='合约销售录入';
		$model=new TradeTreaty;
		if(isset($_POST['TradeTreaty']))
		{
			$model->attributes=$_POST['TradeTreaty'];
			if($model->validate())
			{
				$model->update_staff=Yii::app()->user->id;
				$model->save();
				$this->redirect($this->createUrl('input/newtreatyend'));
			}
		}
		else
		{
			$model->trade_date=date('Y-m-d');
			
		}
		$this->render('newtreaty',array('model'=>$model));
	}
	
	/**
	 * 一般裸机销售
	 */
	public function actionNewgeneral()
	{
		Yii::app()->clientScript->registerScriptFile(Yii::app()->createUrl('js/common'));
		Yii::app()->clientScript->registerScriptFile(Yii::app()->createUrl('js/producttypeProduct'));
		$this->title='裸机销售录入';
		$model=new TradeGeneral;
		if(isset($_POST['TradeGeneral']))
		{
			$model->attributes=$_POST['TradeGeneral'];
			if($model->validate())
			{
				$model->update_staff=Yii::app()->user->id;
				$model->save();
				$this->redirect($this->createUrl('input/newgeneralend'));
			}
		}
		else
		{
			$model->trade_user_type = 5;//设置默认的用户类型
			$model->trade_date=date('Y-m-d');
			$model->trade_number=1;
		}
		$this->render('newgeneral',array('model'=>$model));
	}
	
	/**
	 * 产品外借录入
	 */
	public function actionNewlend()
	{
		Yii::app()->clientScript->registerScriptFile(Yii::app()->createUrl('js/product'));
		$this->title='产品外借录入 ';
		$model=new Lend;
		if(isset($_POST['Lend']))
		{
			$model->attributes=$_POST['Lend'];
			if($model->validate())
			{
				$model->update_staff=Yii::app()->user->id;
				$model->save();
				$this->redirect($this->createUrl('input/newlendend'));
			}
		}
		else
		{
			$model->lend_date=date('Y-m-d');
		}
		$this->render('newlend',array('model'=>$model));
	}
	
	/**
	 * 产品外借录入
	 */
	public function actionNewpurchase()
	{
		Yii::app()->clientScript->registerScriptFile(Yii::app()->createUrl('js/product'));
		$this->title='商品请购录入 ';
		$model=new Purchase;
		if(isset($_POST['Purchase']))
		{
			$model->attributes=$_POST['Purchase'];
			if($model->validate())
			{
				$model->update_staff=Yii::app()->user->id;
				$model->save();
				$this->redirect($this->createUrl('input/newpurchaseend'));
			}
		}
		else
		{
			$model->purchase_date=date('Y-m-d');
			$model->depart_code=Yii::app()->session['currenUser']->depart_code;
		}
		$this->render('newpurchase',array('model'=>$model));
	}
	
	/**
	 * 产品外借录入End
	 */
	public function actionNewpurchaseend()
	{
		//Yii::app()->clientScript->registerScriptFile(Yii::app()->createUrl('js/product'));
		$this->title='商品请购录入';
		$this->render('newpurchaseend');
	}
	
	/**
	 * 产品外借录入end
	 */
	public function actionNewlendend()
	{
		//Yii::app()->clientScript->registerScriptFile(Yii::app()->createUrl('js/product'));
		$this->title='产品外借录入';
		$this->render('newlendend');
	}
	
	/**
	 * 新销售合约机
	 */
	public function actionNewtreatyend()
	{
		//Yii::app()->clientScript->registerScriptFile(Yii::app()->createUrl('js/product'));
		$this->title='合约销售录入';
		$this->render('newtreatyend');
	}
	
	/**
	 * 新一般裸机销售
	 */
	public function actionNewgeneralend()
	{
		//Yii::app()->clientScript->registerScriptFile(Yii::app()->createUrl('js/product'));
		$this->title='裸机销售录入';
		$this->render('newgeneralend');
	}


}